<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://comments">

<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:template match="response" mode="comments">
		<xsl:apply-templates />
		
		<xsl:if test="$userGroup = 'guest'">
			<div>&labelForAddComment; <a href="{$baseURI}/users/login">&labelAuthorization;</a>.</div>
		</xsl:if>
		<xsl:if test="$userGroup != 'guest'">
			<h3 class="write_comment">
				<a href="javascript:void(0);" onclick="showCommentForm (0, '{@type-name}', {@object-id}); return false;">Написать комментарий:</a>
			</h3>
			<div style="display:none;" id="new_comment_0" />
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="object[@type='comment']">
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="userAvatar" select="property[@name='user_avatar']/value" />
		<xsl:param name="allowVote" select="@allow-vote" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<a name="comment{@id}" />
		<div class="comment_item">
			<div id="comment_inner_{@id}">
				<xsl:attribute name="style">
					<xsl:value-of select="concat ('padding-left: ', number(@comment-level) * 50, 'px')" />
				</xsl:attribute>
				
				<xsl:if test="property[@name='deleted']/value = '1'">
					<div class="comment_deleted">&labelDeleted;</div>
				</xsl:if>
				
				<xsl:if test="property[@name='deleted']/value = '0'">
					<div class="comment_header">
						<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id))/data/response/vote" mode="comment-vote" />
						
						<div class="comment_userpic">
							<a href="{$baseURI}/user/{$userLogin}">
								<xsl:if test="$userAvatar = ''">
									<img src="{$baseURI}/images/default-avatar-small.png" alt="" />
								</xsl:if>
								<xsl:if test="$userAvatar != ''">
									<img src="{$baseURI}/thumb_24_24{$userAvatar}" alt="" />
								</xsl:if>
							</a>
						</div>
						
						<a class="username" href="{$baseURI}/user/{$userLogin}">
							<xsl:value-of select="property[@name='user_name']/value" />
						</a>
						<span class="date">
							<xsl:value-of select="property[@name='pubdate']/value" />
						</span>
						
						<a class="comment_anchor" href="#comment{@id}" title="&labelLink;">
							<img src="{$baseURI}/images/anchor.png" align="top" alt="" />
						</a>
						
						<xsl:if test="$userGroup = 'admin' or $userGroup = 'moderator'">
							<a class="comment_delete" href="javascript:void(0)" title="&labelToDelete;" onclick="if (confirm ('&labelDeleteConfirm;'))deleteComment ({@id});">
								<img src="{$baseURI}/images/delete-icon.png" align="top" alt="" />
							</a>
						</xsl:if>
						
					</div>
					<div class="comment_content">
						<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
					</div>
					<xsl:if test="$userGroup != 'guest'">
						<div>
							<xsl:text>(</xsl:text>
							<a href="javascript:void(0);" onclick="showCommentForm ({@id}, '{../@type-name}', {../@object-id}); return false;">&labelReply;</a>
							<xsl:text>)</xsl:text>
						</div>
						<div style="display:none;" id="new_comment_{@id}" />
					</xsl:if>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- VOTE -->
	<xsl:template match="vote" mode="comment-vote">
		<xsl:param name="id" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="rating" select="rating" />
		
		<div class="comment_rating">
			<div class="comment_rating_number" id="comment_rating_{$id}">
				<xsl:if test="number ($rating) &gt; 0">
					<xsl:attribute name="class">comment_rating_number plus</xsl:attribute>
					<xsl:text>+</xsl:text>
				</xsl:if>
				<xsl:if test="number ($rating) &lt; 0">
					<xsl:attribute name="class">comment_rating_number minus</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="$rating" />
			</div>			
			<div>
				<a id="comment_vote_minus_{$id}" href="javascript:void(0);" title="&labelDislike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/comment-vote-minus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '0'">
								<img src="{$baseURI}/images/comment-voted-minus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '0'">
								<img src="{$baseURI}/images/comment-vote-minus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('voteComment (', $id, ', 0);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/comment-vote-minus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
			<div>
				<a id="comment_vote_plus_{$id}" href="javascript:void(0);" title="&labelLike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/comment-vote-plus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '1'">
								<img src="{$baseURI}/images/comment-voted-plus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '1'">
								<img src="{$baseURI}/images/comment-vote-plus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('voteComment (', $id, ', 1);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/comment-vote-plus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>